package main
import (
	"fmt"
	"os"
	"io"
	"bufio"
)

func main(){
	ReadFile("./按行读取文件.go")
}

func ReadFile(filename string){
	f, err := os.Open(filename)
	if err != nil{
		fmt.Println("读取失败，err = ", err)
		return
	}
	defer f.Close()
	
	bf := bufio.NewReader(f)
	
	for i := 1; true; i++{
		buf, err := bf.ReadBytes('\n')
		if err != nil && err != io.EOF{
				fmt.Println("err = ", err)
				return
		}
		fmt.Print(i , "：", string(buf))
		if err == io.EOF{
			break
		}
	}
}